//
//  YMBaseMenuFlowLayout.m
//  SmartCar
//
//  Created by y s on 2022/10/20.
//

#import "YMBaseMenuFlowLayout.h"

@implementation YMBaseMenuFlowLayout



- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{
    NSArray *arrList = [super layoutAttributesForElementsInRect:rect];
    for (NSInteger i = 0; i< arrList.count; i++) {
        if (i > 0) {
            UICollectionViewLayoutAttributes *current = arrList[i];
            UICollectionViewLayoutAttributes *preItem = arrList[i - 1];
            CGFloat originX = CGRectGetMaxX(preItem.frame);
            CGFloat nextOrigin = originX + current.frame.size.width + _maxSpace;
            CGFloat contentWidth = self.collectionViewContentSize.width;
            if (nextOrigin < contentWidth) {
                CGRect tempRect = current.frame;
                tempRect.origin.x = originX + _maxSpace;
                current.frame = tempRect;
            }
        }
    }
    return arrList;
}

@end
